"use strict";

function SetupTooltip(){
	var buildState = $.GetContextPanel().GetAttributeString("buildState","{}");
	var buildTree = $.GetContextPanel().GetAttributeString("buildTree","[]");
	var abilityIndex = $.GetContextPanel().GetAttributeInt("abilityIndex",-1);
	doShow(abilityIndex,JSON.parse(buildState),JSON.parse(buildTree));
}
   
function doShow(abilityIndex,buildState,buildTree){
	$('#attrList').RemoveAndDeleteChildren();
	var itemName = Abilities.GetAbilityName(abilityIndex);

	$('#itemDesc').text = $.Localize("DOTA_Tooltip_ability_"+itemName+"_Description");;
	$('#itemName').text = $.Localize("DOTA_Tooltip_ability_"+itemName);
	var gold = Abilities.GetLevelSpecialValueFor( abilityIndex,"gold",1 );
	var wood = Abilities.GetLevelSpecialValueFor( abilityIndex,"wood",1 );
	var food = Abilities.GetLevelSpecialValueFor( abilityIndex,"food",1 );

	if(gold>0){
		$('#gold').text = $.Localize('#GOLD')+" "+gold;
		$('#gold').visible = true;
	}else{
		$('#gold').visible = false;
	}
	if(wood>0){
		$('#wood').text = $.Localize('#WOOD')+" "+wood;
		$('#wood').visible = true;
	}else{
		$('#wood').visible = false;
	}
	if(food>0){
		$('#food').text = $.Localize('#FOOD')+" "+food;
		$('#food').visible = true;
	}else{
		$('#food').visible = false;
	}

	for(var i in buildTree){
		var panel = $.CreatePanel("Panel", $('#attrList'),buildTree[i]);
	    panel.BLoadLayoutSnippet("attr");
	    var lb = panel.FindChildTraverse("lb_attr");
	    var lbstr = " - "+$.Localize(buildTree[i]);
	    if(buildState["curstate"][buildTree[i]]!=undefined && buildState["curstate"][buildTree[i]]>0){
	    	lb.SetHasClass("build_owned",true);
	    	lbstr+= " √";
	    }else{
	    	lb.SetHasClass("build_owned",false);
	    	lbstr+= " ×";
	    }
	    lb.text = lbstr;
	}

	if(buildState.max_limits!=undefined){
		var panel = $.CreatePanel("Panel", $('#attrList'),"max_limit");
	    panel.BLoadLayoutSnippet("attr");
	    var lb = panel.FindChildTraverse("lb_attr");
	    var lbstr = " · "+$.Localize('#MAX_BUILD')+buildState.max_limits;
	    lb.text = lbstr;
	    lb.SetHasClass("limit_got",buildState.limit_record>=buildState.max_limits)
	}
	if(buildTree.length == undefined || buildTree.length<=0){
		$('#itemNeed').visible = false;
	}else{
		$('#itemNeed').visible = true;
	}
}